package com.tianqu.tms.www.cardect.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.entity.TmsDetectInfo;
/**
 * 待检测（人工）跳转到详细页中转Action
 * 
 * @author tianshifu
 *
 */
public class CarWDPersonDetailDispatchAction extends TmsAction {
	private Logger logger = Logger.getLogger(CarWDPersonDetailDispatchAction.class);//log
	private static final  String CARSERIAL = "carSerial";//页面传过来的车辆ID
	private static final  String CHKMODEL  = "chkModel";//检测模式
	private static final  String CARDETECTID = "carDetectId";//检测报告ID
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		//根据车辆ID查询是否有检测报告,如果没有则跳转到基本信息页。如果有则跳转到对应检测报告详细页
		String forward = "";//跳转路径
		String carSerial = request.getParameter(CARSERIAL);
		TmsDetectInfo entity = TmsDetectInfo.getInstance();
		
		entity  = entity.getWDIpadCarInfoBySerial(carSerial,1);
		if(entity.getCarDetectId()>0)
		{
			uc.removeAttribute(CARDETECTID);
			uc.setAttribute(CARDETECTID, entity.getCarDetectId());//检测报告ID放入uc中
			if(entity.getChkModel() == 1)
			{
				//普通检测
				uc.removeAttribute(CHKMODEL);
				uc.setAttribute(CHKMODEL, "1");
				uc.removeAttribute(CARSERIAL);
				uc.setAttribute(CARSERIAL, carSerial);
				forward = "normalDetectFarword";
				
			}
			if(entity.getChkModel() == 2)
			{
				//高级检测
				uc.removeAttribute(CHKMODEL);
				uc.setAttribute(CHKMODEL, "2");
				uc.removeAttribute(CARSERIAL);
				uc.setAttribute(CARSERIAL, carSerial);
				forward = "seniorDetectFarword";
			}
		}
		else{
			
			//如果没有检测信息则跳转到基本信息详细页
			uc.removeAttribute(CARSERIAL);
			uc.setAttribute(CARSERIAL, carSerial);
			forward = "carInfoDetailFarword";
		}
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(forward); 
	}

}
